{{ template "layout/header" .}}


<main id="body">
    <div class="container">
        <div class="row">
            <div class="col-lg-6 mx-auto">
                <div class="card">
                    <div class="card-header">
                        用户重设密码
                    </div>
                    <div class="card-body">
                        <form action="/api/v1/password/reset" method="post" id="form">
                            <input type="hidden" class="form-control" name="email" id="email" value="{{.email}}">
                            <div class="form-group input-group">
                                <div class="media-body">
                                    <div class="form-group input-group">
                                        <div class="input-group-prepend">
                                            <span class="input-group-text"><i class="icon icon-lock icon-fw"></i></span>
                                        </div>
                                        <input type="password" class="form-control" placeholder="密码" name="password" id="password">
                                    </div>
                                </div>
                            </div>
                            <div class="media">
                                <div class="media-body">
                                    <div class="form-group input-group">
                                        <div class="input-group-prepend">
                                            <span class="input-group-text"><i class="icon icon-lock icon-fw"></i></span>
                                        </div>
                                        <input type="password" class="form-control" placeholder="密码" name="repassword" id="repassword">
                                    </div>
                                </div>
                            </div>
                            <div class="form-group">
                                <button type="button" class="btn btn-primary btn-block" id="registersubmit" data-loading-text="正在提交...">下一步</button>
                            </div>
                            <div class="media">
                                <div>
                                </div>
                                <div class="media-body text-right">
                                    <a href="/login.html" class="text-muted"><small>用户登录</small></a>
                                </div>
                            </div>
                        </form>
                    </div>

                </div>
            </div>
        </div>
    </div>
</main>

<script>
    var jform = $('#form');
    var jsubmit = $('#registersubmit');

    var referer = './';
    jsubmit.on('click', function() {
        var jusername = $('#username').val();
        var jemail = $('#email').val();
        var jpassword = $('#password').val();
        var jrepassword = $('#repassword').val();
        var isused = 0

        if (jpassword != jrepassword){
            $.alert("两次密码不一致")
            return
        }

        // 验证用户密码
        reg = /^(?![A-Za-z]+$)(?![A-Z\d]+$)(?![A-Z\W]+$)(?![a-z\d]+$)(?![a-z\W]+$)(?![\d\W]+$)\S{8,}$/
        matchResult = jpassword.match(reg)
        if (!matchResult) {
            $.alert("用户密码必须包含8位以上大小写字母和数字及特殊字符组合")
            return
        }

        jform.reset();
        jsubmit.button('loading');
        var postdata = jform.serializeObject();
        // postdata.password = $.md5(postdata.password);
        $.xpost(jform.attr('action'), postdata, function(code, message) {
            if (code == 200) {
                $.alert("修改成功,2秒后跳转到登录窗口")
                jsubmit.button(message).delay(1000).location("/login.html");
            } else {
                jform.find('[name="' + code + '"]').alert(message).focus();
                jsubmit.button('reset');
            }
        });
        return false;
    });
</script>
{{ template "layout/footer" }}
